package JaggSoft;

import JaggSoft.Utilidades.*;
import java.awt.*;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.TableRowSorter;
import net.sourceforge.jdatepicker.impl.JDatePickerImpl;

public class ReporteEntrada extends javax.swing.JInternalFrame {

    private JDatePickerImpl selector_fecha_inicial,selector_fecha_final;
    private DefaultListModel<ModeloItemValor> modelo = new DefaultListModel<ModeloItemValor>();
    private JCheckBox jchkFechaInicio,jchkFechaFinal;
    private JFileChooser selector;
    public ReporteEntrada() {
        initComponents();
        this.setLocation(new Point(70, 0));
        selector=new JFileChooser();
        selector.setFileFilter(new FileNameExtensionFilter("Libro de Excel",new String[]{"xls","xlsx"}));
        selector.setMultiSelectionEnabled(false);
        selector.setSelectedFile(new File("reporte_entradas.xls"));
        CargarDatos("");
        CargarProveedores();
        CargarMarcas();
        jlstProductos.setModel(modelo);
        jchkFechaInicio=new JCheckBox("",true);
        jchkFechaFinal=new JCheckBox("",true);
        jchkFechaInicio.setToolTipText("Incluir");
        jchkFechaFinal.setToolTipText("Incluir");
        selector_fecha_inicial = Util.ColocarSelectorFecha(jpFechaInicial, null,new Component[]{jchkFechaInicio});
        selector_fecha_final = Util.ColocarSelectorFecha(jpFechaFinal, null,new Component[]{jchkFechaFinal});
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane3 = new javax.swing.JScrollPane();
        jtblDetalleentrada = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jtfProducto = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtblEntradas = new javax.swing.JTable();
        jScrollPane6 = new javax.swing.JScrollPane();
        jlstProductos = new javax.swing.JList();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jpFechaInicial = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jpFechaFinal = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jcbMarca = new javax.swing.JComboBox();
        jchkMarca = new javax.swing.JCheckBox();
        jLabel6 = new javax.swing.JLabel();
        jcbProveedor = new javax.swing.JComboBox();
        jchkProveedor = new javax.swing.JCheckBox();
        jbtnBuscar = new javax.swing.JButton();
        jbtnExportar = new javax.swing.JButton();

        setClosable(true);
        setMaximizable(true);
        setTitle("Reporte de Entrada");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/Recursos/reporte_entradas.png"))); // NOI18N
        setName("ReporteEntrada"); // NOI18N
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentMoved(java.awt.event.ComponentEvent evt) {
                formComponentMoved(evt);
            }
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });

        jScrollPane3.setViewportView(jtblDetalleentrada);

        jLabel1.setText("Producto:");

        jtfProducto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtfProductoKeyTyped(evt);
            }
        });

        jtblEntradas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtblEntradasMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jtblEntradas);

        jScrollPane6.setViewportView(jlstProductos);

        jLabel3.setText("Fecha Inicial:");

        javax.swing.GroupLayout jpFechaInicialLayout = new javax.swing.GroupLayout(jpFechaInicial);
        jpFechaInicial.setLayout(jpFechaInicialLayout);
        jpFechaInicialLayout.setHorizontalGroup(
            jpFechaInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 168, Short.MAX_VALUE)
        );
        jpFechaInicialLayout.setVerticalGroup(
            jpFechaInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 23, Short.MAX_VALUE)
        );

        jLabel4.setText("Fecha Final:");

        javax.swing.GroupLayout jpFechaFinalLayout = new javax.swing.GroupLayout(jpFechaFinal);
        jpFechaFinal.setLayout(jpFechaFinalLayout);
        jpFechaFinalLayout.setHorizontalGroup(
            jpFechaFinalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 168, Short.MAX_VALUE)
        );
        jpFechaFinalLayout.setVerticalGroup(
            jpFechaFinalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 23, Short.MAX_VALUE)
        );

        jLabel5.setText("Marca:");

        jchkMarca.setToolTipText("Incluir");

        jLabel6.setText("Proveedor:");

        jchkProveedor.setToolTipText("Incluir");

        jbtnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recursos/accion_buscar_mini.png"))); // NOI18N
        jbtnBuscar.setToolTipText("Buscar");
        jbtnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnBuscarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jpFechaInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jbtnBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4)
                                .addComponent(jLabel5)
                                .addComponent(jLabel6))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jcbProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(jchkProveedor))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jcbMarca, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(jchkMarca))
                                .addComponent(jpFechaFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jpFechaInicial, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(15, 15, 15)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jpFechaFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jcbMarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel6)
                                .addComponent(jcbProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jchkProveedor)))
                    .addComponent(jchkMarca))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbtnBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jbtnExportar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recursos/excel.png"))); // NOI18N
        jbtnExportar.setToolTipText("Exportar a Excel");
        jbtnExportar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnExportarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 662, Short.MAX_VALUE)
                    .addComponent(jScrollPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(33, 33, 33)
                                .addComponent(jtfProducto))
                            .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jbtnExportar, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfProducto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addGap(25, 25, 25)
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnExportar, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void CargarProveedores() {
        Util.CargarJComboBox(jcbProveedor,"SELECT id_proveedor,nombre FROM proveedor",new String[]{"id", "nombre"});
    }
    private void CargarMarcas() {
        Util.CargarJComboBox(jcbMarca, "SELECT id_marca,descripcion FROM marca",new String[]{"id", "nombre"});
    }
    private void jtblEntradasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtblEntradasMouseClicked
        if (evt.getClickCount() == 2 && !evt.isConsumed() && jtblEntradas.getSelectedRow() > -1) {
            CargarDatosDetalle(jtblEntradas.getValueAt(jtblEntradas.getSelectedRow(), 0).toString());
        }
    }//GEN-LAST:event_jtblEntradasMouseClicked
    private void jbtnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnBuscarActionPerformed
        String marca = (jchkMarca.isSelected()?((ModeloItemValor)jcbMarca.getSelectedItem()).getValor():"");
        String proveedor = (jchkProveedor.isSelected()?((ModeloItemValor)jcbProveedor.getSelectedItem()).getValor():"");
        
        SimpleDateFormat formato = new SimpleDateFormat("yyyy/MM/dd");
        String fecha_inicial = (jchkFechaInicio.isSelected()?formato.format((Date)selector_fecha_inicial.getModel().getValue()):"");
        String fecha_final = (jchkFechaFinal.isSelected()?formato.format((Date)selector_fecha_final.getModel().getValue()):"");

        ConsultaFiltrada(new String[]{jtfProducto.getText(),marca,proveedor,fecha_inicial,fecha_final});
    }//GEN-LAST:event_jbtnBuscarActionPerformed
    private void formComponentMoved(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentMoved
        if(evt.getComponent().getLocation().x<70)
            evt.getComponent().setLocation(70,evt.getComponent().getLocation().y);
        if(evt.getComponent().getLocation().y<0)
            evt.getComponent().setLocation(evt.getComponent().getLocation().x,0);
    }//GEN-LAST:event_formComponentMoved
    private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
        if(this.getParent().getWidth()-70<this.getWidth()  && this.isMaximum)
            this.setSize(this.getWidth()-70,this.getHeight());
    }//GEN-LAST:event_formComponentResized
    private void jtfProductoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfProductoKeyTyped
        modelo.removeAllElements();
        JTable tabla = Conexion.ObtenerTabla("SELECT i.id_inventario,CONCAT_WS(' ',p.nombre,i.unidad_medida,i.detalle) AS descripcion FROM inventario i INNER JOIN producto p ON i.id_producto=p.id_producto WHERE p.nombre LIKE '" + Util.ComponerTexto(jtfProducto.getText()+evt.getKeyChar())+ "%'",new String[]{"id","descripcion"});
        for (int i = 0; i < tabla.getRowCount(); i++) 
            modelo.addElement(new ModeloItemValor(tabla.getValueAt(i, 1), tabla.getValueAt(i, 0)));
    }//GEN-LAST:event_jtfProductoKeyTyped

    private void jbtnExportarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnExportarActionPerformed
        if(jtblEntradas.getRowCount()>0){
            if(selector.showSaveDialog(null)==JOptionPane.OK_OPTION){
                try {
                    String ruta=selector.getSelectedFile().getAbsolutePath();
                    if(!ruta.endsWith(".xls"))
                        ruta+=".xls";
                    File archivo_excel=new File(ruta);
                    switch(Util.ExportarReporteExcel(jtblEntradas,archivo_excel,"Reporte Entradas",
                            "SELECT CONCAT_WS(' ',pr.nombre,i.unidad_medida,i.detalle) AS producto,m.descripcion,p.nombre,de.cantidad,"
                            +"de.precio_unidad_medida FROM detalleentrada de INNER JOIN inventario i ON de.id_inventario=i.id_inventario INNER JOIN marca m "
                            +"ON de.id_marca=m.id_marca INNER JOIN proveedor p ON de.id_proveedor=p.id_proveedor INNER JOIN producto pr "
                            +"ON i.id_producto=pr.id_producto WHERE de.id_entrada=@id ORDER BY pr.nombre;",new String[]{"Producto","Marca","Proveedor","Cantidad","Precio"})){
                        case OK:
                        JOptionPane.showMessageDialog(null,"Archivo Exportado",this.getTitle(),JOptionPane.INFORMATION_MESSAGE);
                        Desktop.getDesktop().open(archivo_excel);
                        break;
                        case CANCELADO:
                        break;
                        case ERROR:
                        JOptionPane.showMessageDialog(null,"No se pudo exportar el archivo","Error",JOptionPane.ERROR_MESSAGE);
                        break;
                    }
                } catch (Exception ex) {System.err.println(ex.getMessage());}
            }
        }
        else
            JOptionPane.showMessageDialog(null,"No hay datos para exportar","Sin Datos",JOptionPane.WARNING_MESSAGE);
    }//GEN-LAST:event_jbtnExportarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JButton jbtnBuscar;
    private javax.swing.JButton jbtnExportar;
    private javax.swing.JComboBox jcbMarca;
    private javax.swing.JComboBox jcbProveedor;
    private javax.swing.JCheckBox jchkMarca;
    private javax.swing.JCheckBox jchkProveedor;
    private javax.swing.JList jlstProductos;
    private javax.swing.JPanel jpFechaFinal;
    private javax.swing.JPanel jpFechaInicial;
    private javax.swing.JTable jtblDetalleentrada;
    private javax.swing.JTable jtblEntradas;
    private javax.swing.JTextField jtfProducto;
    // End of variables declaration//GEN-END:variables
    private void CargarDatosDetalle(String id) {
        String consulta = "SELECT CONCAT_WS(' ',pr.nombre,i.unidad_medida,i.detalle) AS producto,m.descripcion,p.nombre,de.cantidad,"
                + "de.precio_unidad_medida FROM detalleentrada de INNER JOIN inventario i ON de.id_inventario=i.id_inventario INNER JOIN marca m "
                + "ON de.id_marca=m.id_marca INNER JOIN proveedor p ON de.id_proveedor=p.id_proveedor INNER JOIN producto pr "
                + "ON i.id_producto=pr.id_producto WHERE de.id_entrada="+id+" ORDER BY pr.nombre;";
        Util.CargarTabla(jtblDetalleentrada, consulta, new String[]{"Producto", "Marca", "Proveedor", "Cantidad", "Precio"});
        Util.AlinearColumnas(jtblDetalleentrada, SwingConstants.CENTER);
        jtblDetalleentrada.setRowSorter(new TableRowSorter<MyModeloTabla>((MyModeloTabla) jtblDetalleentrada.getModel()));
    }
    private void CargarDatos(String filtro) {
        String consulta = "SELECT id_entrada,DATE_FORMAT(fecha_ingreso,'%d/%m/%Y') AS fecha_ingreso,observaciones FROM entrada"+filtro;
        Util.CargarTabla(jtblEntradas, consulta, new String[]{"Código", "Fecha de Ingreso", "Observaciones"});
        Util.AlinearColumnas(jtblEntradas, SwingConstants.CENTER);
        jtblEntradas.setRowSorter(new TableRowSorter<>((MyModeloTabla) jtblEntradas.getModel()));
    }
    private void ConsultaFiltrada(String datos[]) {
        String filtro="";
        String producto = (!datos[0].equals("") ? " WHERE p.nombre LIKE '" + Util.ComponerTexto(datos[0]) + "%'" : "");
        String marca = (!datos[1].equals("") ? (!producto.equals("") ? " AND" : " WHERE") + " de.id_marca = '" + datos[1] + "'" : "");
        String proveedor = (!datos[2].equals("") ? (!(producto+marca).equals("") ? " AND" : " WHERE") + " de.id_proveedor = '" + datos[2] + "'" : "");
        String fecha_ini = (!datos[3].equals("") ? ((producto+marca+proveedor).equals("") ? " WHERE":" AND")+" fecha_ingreso >= '" + datos[3] + "'" : "");
        String fecha_fin = (!datos[4].equals("") ? ((producto+marca+proveedor+fecha_ini).equals("") ? " WHERE" : " AND") + " fecha_ingreso <= '" + datos[4] + "'" : "");
        filtro=(!(producto+marca+proveedor).equals("")?" WHERE id_entrada IN (SELECT DISTINCT de.id_entrada "
                +"FROM detalleentrada de INNER JOIN inventario i ON de.id_inventario=i.id_inventario INNER JOIN producto p "
                +"ON i.id_producto=p.id_producto"+producto+marca+proveedor+")":filtro);
        filtro=(!(fecha_ini+fecha_fin).equals("")?filtro+fecha_ini+fecha_fin:filtro);
        CargarDatos(filtro + " ");
    }
}